/* eslint-disable no-unused-vars */
/**
 * 顶点类型放大缩小样式
 */

import namespace from "./namespace";

class VertexResizeHandle extends namespace.ResizeHandle {
  NAME = `${namespace.namespace}.VertexResizeHandle`;

  constructor(owner, index) {
    super({ owner });
    this.index = index;
  }

  onDragStart() {
    super.onDragStart();
    this.shape.attr({ cursor: "crosshair" });
    this.vertex = this.owner.getVertex(this.index).clone();
  }

  onDrag(dx, dy, dx2, dy2) {
    this.setPosition(this.x + dx2, this.y + dy2);
    this.vertex.translate(dx2, dy2);
    let newPos = this.vertex.clone();
    this.owner.setVertex(this.index, newPos.x, newPos.y);
  }

  onDragEnd() {
    this.shape.attr({ cursor: "move" });
  }

  updateLocation() {
    let resizeWidthHalf = this.getWidth() / 2;
    let resizeHeightHalf = this.getHeight() / 2;

    let anchor = this.owner.getVertex(this.index);

    // 设置矩形中心点 为顶点坐标
    this.setPosition(anchor.x - resizeWidthHalf, anchor.y - resizeHeightHalf);
  }
}

namespace.VertexResizeHandle = VertexResizeHandle;
